//
//  StdString_to_Subscription.cpp
//  sad
//
//  Created by Christopher Kemsley on 2/5/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//



#include "Codec.hpp"
#include "PLISTParser.hpp"
#include "URL.hpp"
#include "Settings.hpp"

#include "PubSub.hpp"
#include "SystemCDefinitions.hpp"






// This is a combinatorial type. Converts
// URL -> PLIST -> Settings
struct StdString_to_sc_signal_SCLogic_Subscription : public aCodec < Subscription < sc_signal<SCLogic> >* , std::string >
{
	StdString_to_sc_signal_SCLogic_Subscription ()
	:	aCodec < Subscription < sc_signal<SCLogic> >* , std::string > ()
	{ }
	
	
	virtual bool	runDecode		( Any const & anyView , Any const & anyModel )
		{
		std::string const&			name	=	anyView.as<std::string>() ;
		
		if ( name.size() != 0 )
			{
			Log::notice("StdString_to_sc_signal_SCLogic_Subscription") << "Codec linked string (probably from plist) to logic signal: " << name ;
			
			Subscription<sc_signal<SCLogic> >&	sub		=	*anyModel.as < Subscription < sc_signal<SCLogic> > * > () ;
			
			sub = name ;
			
			return true ;
			}
		else
			{
			Log::warning("StdString_to_sc_signal_SCLogic_Subscription") << "Codec failed linking string (probably from plist) to logic signal (zero length)" ;
			}
		
		return false ;
		}
	
} ;
StdString_to_sc_signal_SCLogic_Subscription _StdString_to_sc_signal_SCLogic_Subscription ;







// This is a combinatorial type. Converts
// URL -> PLIST -> Settings
struct StdString_to_sc_signal_SCLogic_Publication : public aCodec < Publication < sc_signal<SCLogic> >* , std::string >
{
	StdString_to_sc_signal_SCLogic_Publication ()
	:	aCodec < Publication < sc_signal<SCLogic> >* , std::string > ()
	{ }
	
	
	virtual bool	runDecode		( Any const & anyView , Any const & anyModel )
		{
		std::string const&			name	=	anyView.as<std::string>() ;
		
		if ( name.size() != 0 )
			{
			Log::notice("StdString_to_sc_signal_SCLogic_Publication") << "Codec linked string (probably from plist) to logic signal: " << name ;
			
			Publication<sc_signal<SCLogic> >&	sub		=	*anyModel.as < Publication < sc_signal<SCLogic> > * > () ;
			
			sub = name ;
			
			return true ;
			}
		else
			{
			Log::warning("StdString_to_sc_signal_SCLogic_Publication") << "Codec failed linking string (probably from plist) to logic signal (zero length)" ;
			}
		
		return false ;
		}
	
} ;
StdString_to_sc_signal_SCLogic_Publication _StdString_to_sc_signal_SCLogic_Publication ;



